package com.norbitltd.guavaleaves.java.lang;

import com.google.common.base.Function;

public class ObjectFunctions {
	
	public static final <T extends Object> Function<T, T> defaultNull(final T defaultValue) {
		return new Function<T, T>() {
			public T apply(T input) {
				return input == null  ? defaultValue : input; 
			};
		};
	}

	public static final Function<Object, String> convertToString() {
		return new Function<Object, String>() {
			public String apply(Object input) {
				if( input == null ) {
					return null;
				} else {
					return input.toString();	
				}
			}
		};
	}
	
	public static final Function<Object, Integer> getHashCode(){
		return new Function<Object, Integer>() {
			public Integer apply(Object input) {
				if( input == null ) {
					return null;
				} else {
					return input.hashCode();	
				}
			}
		};
	}
	
	public static final Function<Object, Class<?>> getClassObject(){
		return new Function<Object, Class<?>>() {
			public Class<?> apply(Object input) {
				if( input == null ) {
					return null;
				} else {
					return input.getClass();
				}
			}
		};
	}
}
